from sys import stdout
import os
import logging


LOG_FILES_DIR = './log'
if not os.path.exists(LOG_FILES_DIR):
    os.makedirs(LOG_FILES_DIR)
log_filename = 'run.log'    # Because sanic use multiprocess module, this filename can not different in all processes.
# log_filename = datetime.now().strftime("%Y-%m-%d_%H:%M:%S.log")


formatter = logging.Formatter(
    "%(asctime)s[%(levelname)s](%(name)s): %(message)s",
    "[%Y-%m-%d %H:%M:%S %z]"
)

console = logging.StreamHandler(stdout)
console.setFormatter(formatter)

file_handler = logging.FileHandler(
    f'{LOG_FILES_DIR}/{log_filename}',
    encoding='utf-8'
)
file_handler.setFormatter(formatter)
file_handler.setLevel(logging.DEBUG)
